package org.example.producer;

import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

import java.nio.charset.StandardCharsets;

/**
 * @Author: tang
 * @Description:
 * @Date 2025/8/21 15:53
 */
@Slf4j
public class SimpleProducer {
    public static void main(String[] args) throws Exception{

        DefaultMQProducer producer = new DefaultMQProducer("default");
        producer.setNamesrvAddr("localhost:9876");
        producer.start();

        for (int i = 0; i < 50; i++) {
            Message message = new Message("test-topic",
                    ("Hello RocketMQ " + i).getBytes(StandardCharsets.UTF_8));
            SendResult sendResult = producer.send(message);
            System.out.println(sendResult);
        }
        log.info("producer.start...");
        producer.shutdown();

    }
}
